package com.qianfeng.camerademo.adapter;

import java.util.ArrayList;

import com.lidroid.xutils.ViewUtils;
import com.lidroid.xutils.view.annotation.ViewInject;
import com.qianfeng.camerademo.R;
import com.qianfeng.camerademo.bean.UploadImageBean;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.CheckBox;
import android.widget.ImageView;

/**
 * @author: 张唯
 * @类 说 明:
 * @version 1.0
 * @创建时间：2014-10-28 下午5:37:57
 * 
 */
public class ShowImageAdapter extends BaseAdapter {
	private ArrayList<UploadImageBean> bitmaps;
	private LayoutInflater inflater;

	public ShowImageAdapter(ArrayList<UploadImageBean> bitmaps, Context context) {
		super();
		this.bitmaps = bitmaps;
		inflater = LayoutInflater.from(context);
	}

	@Override
	public int getCount() {
		return bitmaps.size();
	}

	@Override
	public Object getItem(int position) {
		return bitmaps.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder vh = null;
		if (convertView == null) {
			convertView = inflater.inflate(R.layout.show_item_layout, null);
			vh = new ViewHolder();
			ViewUtils.inject(vh, convertView);
			convertView.setTag(vh);
		} else {
			vh = (ViewHolder) convertView.getTag();
		}
		if (bitmaps.get(position).isShow()) {
			vh.cb.setChecked(true);
		} else {
			vh.cb.setChecked(false);
		}
		vh.iv.setImageBitmap(bitmaps.get(position).getBitmap());

		return convertView;
	}

	public static class ViewHolder {
		@ViewInject(R.id.upload_images)
		public ImageView iv;
		@ViewInject(R.id.upload_checkbox)
		public CheckBox cb;

	}

}
